package str

func lengthOfLongestSubstring(s string) int {

	res := -1
	left, right := 0, 0
	charMap := map[byte]int{} // 用于记录之前遇到过的字符

	for right < len(s) {
		for right < len(s) {
			if _, ok := charMap[s[right]]; ok {
				break
			}
			charMap[s[right]] = 1
			right++
		}

		len := right - left
		if len > res {
			res = len
		}

		delete(charMap, s[left]) // 删除左指针的字符
		left++

	}

	return res

}
